/**
 * projectName: waste_recovery-version_management
 * fileName: MySwaggerResourceProvider.java
 * packageName: com.damie.gateway.config
 * date: 2021-01-20 5:52 下午
 * copyright(c) 2017-2020 xxx公司
 */
package com.damie.gateway.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;

import java.util.*;

/**
 * 聚合各个服务的swagger接口
 *
 * @author ksyzz
 * @since <pre>2019/04/09</pre>
 */
@Component
public class MySwaggerResourceProvider implements SwaggerResourcesProvider {

    /**
     * swagger2默认的url后缀
     */
    private static final String SWAGGER2URL = "/v2/api-docs";

    /**
     * 网关路由
     */
    private final RouteLocator routeLocator;

    /**
     * 网关应用名称
     */
    @Value("${spring.application.name}")
    private String self;

    @Autowired
    public MySwaggerResourceProvider(RouteLocator routeLocator) {
        this.routeLocator = routeLocator;
    }

    //该接口的方法就是获取分类数据的集合

    @Override
    public List<SwaggerResource> get() {
        return Arrays.asList(
        createSwaggerResource("用户中心","/user-web/v2/api-docs","2.0"),
        createSwaggerResource("后台管理中心","/boss-service/v2/api-docs","2.0"),
        createSwaggerResource("站点中心","/site/v2/api-docs","2.0"),
        createSwaggerResource("积分商城中心","/damie-shop-web/v2/api-docs","2.0")
        );
    }
        //集合里面的每一个数据就是一个对象
        private SwaggerResource createSwaggerResource(String name,String url,String version) {
            SwaggerResource sr = new SwaggerResource();
            sr.setName(name);
            sr.setLocation(url);
            sr.setSwaggerVersion(version);
        return sr;
    }
}

